home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2004 August
/
Chip_2004-08_cd1.bin
/
oddech
/
hexxagon
/
Neave Hexxagon.exe
/
scripts
/
frame_4
/
DoAction.as
Wrap
Text File
|
2003-10-01
|
10KB
|
445 lines
function updateGame(newPlayer)
{
if(newPlayer)
{
score4 = score6 = 0;
}
var nextPlayer = player >= 5 ? 4 : 6;
var noMoves = true;
var i = 22;
while(i < 111)
{
if(newPlayer && noMoves && _root["Hexx" + i]._currentframe == nextPlayer)
{
var j = 0;
while(j < 18)
{
if(_root["Hexx" + (all[j] + i)]._currentframe == 1)
{
noMoves = false;
j = 18;
}
j++;
}
}
tellTarget("Hexx" + i)
{
if(3 < _currentframe)
{
if(_currentframe == 5 || _currentframe == 7)
{
prevFrame();
}
if(newPlayer)
{
_root["score" + _currentframe]++;
if(_root.player == 4 && !_root.compPlay)
{
HexxButtonP1._visible = false;
HexxButtonP2._visible = true;
}
else if(_root.player == 6)
{
HexxButtonP1._visible = true;
HexxButtonP2._visible = false;
}
}
}
else
{
gotoAndStop("Off");
}
}
i++;
}
if(newPlayer)
{
if(noMoves)
{
score4 = score6 = 0;
var i = 22;
while(i < 111)
{
tellTarget("Hexx" + i)
{
if(_currentframe == 1)
{
gotoAndStop(_root.player);
}
_root["score" + _currentframe]++;
HexxButtonP1._visible = HexxButtonP2._visible = false;
}
i++;
}
if(score4 == score6)
{
Winner.gotoAndStop("Tie");
}
else if(score6 < score4)
{
Winner.gotoAndPlay("Win4");
player = 6;
}
else
{
Winner.gotoAndPlay("Win6");
player = 4;
}
Winner._visible = true;
}
var b = 4;
while(b < 8)
{
tellTarget("Bar" + b)
{
_width = _root["score" + b];
_X = 362 - _width / 2;
}
b += 2;
}
if(compAttack)
{
Bulb.play();
}
compAttack = false;
if(compPlay && !noMoves && attack && player != computer)
{
compAttack = true;
}
else
{
Turn.gotoAndStop(player / 2);
startDrag("Turn",1);
}
}
}
function playAnim(plyr)
{
Turn.gotoAndStop(1);
stopDrag();
if(remove)
{
_root["Hexx" + unselect].gotoAndStop("Off");
remove = false;
lastHexx = hexx;
}
notRev = true;
tellTarget("P" + plyr)
{
dirn = _root.hexx - _root.unselect;
mover = _root.unselect;
if(plyr == 4 && dirn < 0)
{
mover = _root.hexx;
}
_X = _root["Hexx" + mover]._x;
_Y = _root["Hexx" + mover]._y;
var d = 0;
while(d < 6)
{
if(dirn == _root.double[d])
{
if(plyr == 6)
{
_root.Snd.gotoAndPlay("P2Double");
gotoAndPlay(7 * d + 9);
}
else
{
if(0 < dirn)
{
gotoAndPlay(17 * d + 2);
}
else
{
_root.notRev = false;
gotoAndPlay(17 * d - 33);
Rewinder.gotoAndPlay(2);
}
_root.Snd.gotoAndPlay("P1Move");
}
}
d++;
}
var d = 0;
while(d < 12)
{
if(dirn == _root.jump[d])
{
if(plyr == 6)
{
_root.animPos = 7 * d + 51;
gotoAndPlay(2);
}
else
{
if(0 < dirn)
{
gotoAndPlay(17 * d + 53);
}
else
{
_root.notRev = false;
gotoAndPlay(17 * d - 33);
Rewinder.gotoAndPlay(2);
}
_root.Snd.gotoAndPlay("P1Move");
}
}
d++;
}
}
if(compAttack)
{
Bulb.gotoAndStop(1);
}
}
function moveAnim(dest, plyr)
{
_root["P" + plyr]._x = _root["Hexx" + dest]._x;
_root["P" + plyr]._y = _root["Hexx" + dest]._y;
}
function attackHexx(dest, plyr)
{
_root["Hexx" + dest].gotoAndStop(plyr);
_root["P" + plyr].gotoAndStop("Zap");
var noAttack = true;
var i = 0;
while(i < 6)
{
var toZap = false;
tellTarget("Hexx" + (dest + double[i]))
{
if(3 < _currentframe && _currentframe != plyr)
{
noAttack = false;
toZap = true;
gotoAndStop(plyr);
Wobble.gotoAndStop("Morph");
}
}
_root["P" + plyr]["Zap" + double[i]]._visible = toZap;
i++;
}
if(noAttack)
{
_root["P" + plyr].gotoAndStop(1);
_root["Hexx" + dest].Wobble.gotoAndStop("Sparkle");
}
}
function playerSelect(hexx)
{
if(compAttack || attack && player == _root["Hexx" + hexx]._currentframe)
{
return undefined;
}
_root.hexx = hexx;
attack = remove = false;
tellTarget("Hexx" + hexx)
{
if(_currentframe == 4 || _currentframe == 6)
{
_root.player = _currentframe;
_root.unselect = hexx;
nextFrame();
}
else if(_currentframe == 2)
{
_root.attack = true;
_root.lastHexx = hexx;
}
else if(_currentframe == 3)
{
_root.attack = _root.remove = true;
_root.lastHexx = hexx;
}
}
updateGame(false);
if(attack)
{
playAnim(player);
}
else
{
Snd.gotoAndPlay("Select");
}
if(lastHexx != hexx)
{
lastHexx = hexx;
_root["Hexx" + hexx].nextFrame();
var i = 0;
while(i < 6)
{
tellTarget("Hexx" + (hexx + double[i]))
{
if(_currentframe < 4)
{
gotoAndStop("Double");
}
}
tellTarget("Hexx" + (hexx + jump[i]))
{
if(_currentframe < 4)
{
gotoAndStop("Jump");
}
}
tellTarget("Hexx" + (hexx + jump[i + 6]))
{
if(_currentframe < 4)
{
gotoAndStop("Jump");
}
}
i++;
}
}
else
{
lastHexx = 0;
}
}
function findBestMove(compHexx)
{
highestRanking = hexxOrig = hexxDest = eqCount = 0;
var check = 0;
while(check < 3)
{
var j = 0;
while(j < 6)
{
attackCount = 0;
if(check == 0)
{
hexxCheck = double[j];
if(Math.round(Math.random() * 1.5))
{
attackCount = 0.5;
}
else
{
attackCount = 1.5;
}
}
else if(check == 1)
{
hexxCheck = jump[j];
}
else if(check == 2)
{
hexxCheck = jump[j + 6];
}
var k = 0;
while(k < 6)
{
tryDest = compHexx + hexxCheck;
if(_root["Hexx" + tryDest]._currentframe == 1)
{
if(_root["Hexx" + (tryDest + double[k])]._currentframe == player)
{
this.attackCount = this.attackCount + 1;
}
}
k++;
}
if(attackCount >= highestRanking)
{
if(_root["Hexx" + tryDest]._currentframe == 1)
{
highestRanking = attackCount;
hexxDest = tryDest;
}
}
if(attackCount == highestRanking)
{
eqCount = 0;
var k = 0;
while(k < 6)
{
if(_root["Hexx" + (compHexx + double[k])]._currentframe == computer)
{
eqCount++;
}
else
{
eqCount--;
}
k++;
}
}
j++;
}
check++;
}
return [highestRanking,compHexx,hexxDest,eqCount];
}
function computerSelect()
{
thisBest = new Array(0,0,0,0);
bestMove = new Array(0,0,0,0);
var i = 22;
while(i < 111)
{
compHexx = 0;
if(_root["Hexx" + i]._currentframe == computer)
{
compHexx = i;
}
if(compHexx)
{
thisBest = findBestMove(compHexx);
if(bestMove[0] < thisBest[0])
{
bestMove = thisBest;
}
else if(thisBest[0] == bestMove[0] && thisBest[3] < bestMove[3])
{
bestMove = thisBest;
}
}
i++;
}
if(bestMove[0])
{
if(bestMove[0] - int(bestMove[0]) != 0.5)
{
remove = true;
}
unselect = bestMove[1];
hexx = bestMove[2];
player = computer;
playAnim(computer);
}
}
stop();
Mouse.hide();
double = new Array(10,11,1,-10,-11,-1);
jump = new Array(9,20,21,22,12,2,-9,-20,-21,-22,-12,-2);
all = jump.concat(double);
attack = compAttack = remove = false;
notRev = true;
player = 4;
computer = 6;
score4 = 3;
score6 = 3;
unselect = 0;
hexx = 0;
lastHexx = 0;
animPos = 1;
Hexx22.gotoAndStop("On1");
Hexx70.gotoAndStop("On1");
Hexx106.gotoAndStop("On1");
Hexx26.gotoAndStop("On2");
Hexx62.gotoAndStop("On2");
Hexx110.gotoAndStop("On2");
Hexx26.HexxButtonP2._visible = Hexx62.HexxButtonP2._visible = Hexx110.HexxButtonP2._visible = false;
var i = 1;
while(i < 133)
{
duplicateMovieClip("Hexx0","Hexx" + i,16384 + i);
i++;
}
s = new Sound();
startDrag("Turn",1);
Turn.gotoAndStop(3);